<link rel="stylesheet" href="<%- Virtual_Path.Static %>main/css/forget.css">
<div class="xiu-container">
    <div class="forget-main" id="bd-forgot">
        <div class="forget-t">
            <h1>找回密码</h1>
        </div>
        <div class="forget-m">
            <div class="group-content">
                <div class="group-item">
                    <input type="text" name="Found_Phone" value="" placeholder="请输入绑定手机号" class="input">
                </div>
                <div class="group-item">
                    <input type="text" name="Found_Phone_VerifyCode" value="" placeholder="请输入验证码"
                           class="input input-Verificationcode">
                    <!--<input type="button" value="获取验证码" placeholder="获取验证码"  class="input input-getcode"/>-->
                    <a href="javascript:;" class="input input-getcode ForGot_PhoneCode"
                       id="btnMainUser_Forgot_PhoneVerifyCode" name="1">获取验证码</a>
                </div>
                <div class="group-item">
                    <input type="submit" id="J_UserPassword_Forgot_sub" class="button-normal button-next" value="下一步">
                </div>
            </div>

        </div>
    </div>
</div>

<script>
    $(function () {
        if (_StateData.IsLogin) {
            $.CommonMain.Modal_Tip('用户已经登录', {Timeout: 1000});
            location.href = '/';
        }
        $("#bd-forgot").show();
        //发送验证码
        $('#btnMainUser_Forgot_PhoneVerifyCode').click(function () {
            var _Button = $(this);
            if (_Button.hasClass('disable')) {
                return;
            }
            var _Phone =  $('input[name="Found_Phone"]');
            var _PhoneNumber = _Phone.val();
            if (!(/^1\d{10}$/).test(_PhoneNumber)) {
                _Phone.focus();
                $.KOC.Tips.Open('Error', '请输入正确的手机号', {Timeout: 3000});
                return;
            }
            $.Common.PhoneVerifyCode.fnSend(_PhoneNumber, function () {
                //成功
                $.KOC.Tips.Open('Success', '验证短信已经发送至:' + _PhoneNumber + ',请注意查收', {Timeout: 2000});
                $.Common.PhoneVerifyCode.fnCountdown(function (Interval) {
                    _Button.addClass('disable');
                    if (Interval <= 0) {
                        _Button.removeClass('disable').text('重新获取验证码');
                    } else {
                        _Button.text(Interval + '秒后重新获取');
                    }
                });
            });
        });
        $('#J_UserPassword_Forgot_sub').on('click', function () {
            var params = {};
            var tel = /^0?(13[0-9]|15[012356789]|18[0123456789]|17[0123456789]|14[57])[0-9]{8}$|^[a-zA-Z0-9][a-zA-Z0-9._-]*\@[a-zA-Z0-9]+\.[a-zA-Z0-9\.]+$/;
            params.Phone = $.trim($('input[name="Found_Phone"]').val());
            params.VerifyCode = $.trim($('input[name="Found_Phone_VerifyCode"]').val());
            if (!params.Phone) {
                $.CommonMain.Modal_Tip('请输入手机号', {Timeout: 2000});
                $('input[name="Found_Phone"]').focus();
                return false;
            }
            if (!tel.test(params.Phone)) {
                $.CommonMain.Modal_Tip('你输入的手机号格式不正确', {Timeout: 2000});
                $('input[name="Found_Phone"]').focus();
                return false;
            }
            if (!params.VerifyCode) {
                $.CommonMain.Modal_Tip('请输入你的验证码', {Timeout: 2000});
                $('input[name="Found_Phone_VerifyCode"]').focus();
                return false;
            }
            $.KOC.Loading.Open();
            $.ajax({
                url: '/ajax/user.user-info.checkphone',
                type: 'post',
                dataType: 'json',
                data: {
                    Phone: params.Phone,
                    VerifyCode: params.VerifyCode
                },
                success: function (data) {
                    $.KOC.Loading.Close();
                    if (data.flag !== 0) {
                        $.CommonMain.Modal_Tip(data.msg + "(" + data.flag + ")", {Timeout: 2000});
                        return;
                    }
                    var url = "./step2?Phone=" + params.Phone;
                    location.href = url;
                }
            });
        });
    });
</script>